// pages/ciba/ciba.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    windowHeight: '',
    windowWidth: '',
    scrollViewHeight: "",
    code: '',
    date: '',
    ciba: '',
    cibaEn: '',
    imgurl: '',
    error: ''
  },
  onShareAppMessage: function () {

    return {

      title: '每日英语',

      desc: '每日一句精彩英语',

      path: '/pages/ciba/ciba'

    }

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    var that = this;

    //显示加载动画
    wx.showLoading({
      title: '正在加载',
    });

    // //获取屏幕高度
    wx.getSystemInfo({
      success: function (res) {
        console.log(res.windowHeight);
        that.setData({
          scrollViewHeight: res.windowHeight - 10,
          windowHeight: res.windowHeight - 10,
          windowWidth: res.windowWidth - 10
        });
      }
    });
    //发送请求，获取每日一言
    wx.request({
      //请求api地址
      url:"http://freecityid.market.alicloudapi.com/whapi/json/alicityweather/briefforecast3days",
      // data: {
      //   province: 甘肃
      // },
      method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT  
      // header: {}, // 设置请求的 header  
      Header: { "Host": "freecityid.market.alicloudapi.com", "X-Ca-Timestamp": "1559637890329", "gateway_channel": "http", "X-Ca-Request-Mode": "debug", "X-Ca-Key": "203714822", "X-Ca-Stage": "RELEASE", "x-ca-nonce": "3d76b094-ad36-4433-8b4a-2e8c92993b6c", "Content-Type": "application/x-www-form-urlencoded; charset=utf-8", "Authorization": "APPCODE 8f62b5362c3f42d5931ec23968f9a587" },
      Body: { "cityId": "2", "token": "677282c2f1b3d718152c4e25ed434bc4" },
      //返回数据处理
      success: function (res) {
        //处理api返回的数据
        var msg = res.data;
        console.log('begin---');
        // console.log(msg);
        console.log("success:返回URL:" + msg.imgurl);
        console.log('---end');
        try {
          that.setData({
            code: msg['code'],
            date: msg['date'],
            ciba: msg['ciba'],
            cibaEn: msg['ciba-en'],
            imgurl: msg['imgurl']
          });

        } catch (e) {
          that.setData({
            hitokoto: "网络故障，请检查网络"
          });
        }
        wx.hideLoading();
      },
      fail: function (err) {
        console.log("error:" + err);
        that.setData({
          error: "opps'.....网络故障，请检查网络"
        });
        wx.hideLoading();
      }
    });

  },
})